//
//  MapViewController.m
//  HeartTravel
//
//  Created by dlios on 15-7-2.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MapViewController.h"
#import "CustomAnnotation.h"
#import <MapKit/MapKit.h>
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface MapViewController ()<MKMapViewDelegate,CLLocationManagerDelegate>
{
    MKMapView *map;
    CLLocationManager *locationManager;
}

@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//   添加地图
    map = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 49 - 64)];
    map.showsUserLocation = YES;
    map.mapType = MKMapTypeStandard;
    [self.view addSubview:map];
    
//    定位到前一页面地方的位置
    NSLog(@"%@",self.x);
    NSLog(@"%@",self.y);
    CLLocationDegrees x = [self.x doubleValue];
    CLLocationDegrees y =[self.y doubleValue];
    CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(x,y);
    float zoomLevel = 0.02;
    MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomLevel, zoomLevel));
    [map setRegion:[map regionThatFits:region] animated:YES];
    
    [self createAnnotationWithCoord:coords];
    
//    定位到当前位置并获取当前经纬度
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager startUpdatingLocation];
    
}

- (void)createAnnotationWithCoord:(CLLocationCoordinate2D)coords{
    CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinate:coords];
    annotation.title = self.titleName;
    [map addAnnotation:annotation];
}

//获得当前位置的经纬度



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
